package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.DiningTable;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/** 餐桌管理
 * @ProjectName: MyHotelProject
 * @Package: com.xuetang9.t9.hotel.mappers
 * @ClassName: IDiningTableMapper
 * @Author: ChinaHp
 * @Description:
 * @Date: 2020/2/24 14:23
 * @Version: 1.0
 */
public interface IDiningTableMapper {
    /**
     * 天剑
     * @param diningTable
     * @return
     */
    @Insert("Insert into diningtable(typeId,name) value (#{typeId},#{typeId})")
    int insert(DiningTable diningTable);

    /*
     * @Description 就餐
     * @param tableNum
     * @return int
     * @date 2020/3/11 16:43
     * auther ASUS
     */
    @Update("update diningtable set state = '就餐中' where tableNum = #{tableNum}")
    int updateTableState(@Param("tableNum") int tableNum);

    /**
     * 通过餐桌id查询餐桌
     * @param tableNum
     * @return
     */
    @Select("select * from diningtable where tableNum=#{tableNum}")
    DiningTable select(@Param("tableNum") int tableNum);

    /**
     * 通过餐桌类型id获取餐桌
     * @param typeId
     * @return
     */
    @Select("select * from diningtable where typeId = #{typeId}")
    @Results(value = {
            @Result(property = "tableType", column = "typeId",one = @One(select = "com.xuetang9.t9.hotel.mapper.ITableTypeMapper.select",fetchType = FetchType.EAGER))
    })
    List<DiningTable> selectType(@Param("typeId") int typeId);

    /**
     * 修改餐桌
     * @param diningTable
     * @return
     */
    @Update("update diningtable set typeId = #{typeId},name = #{name},state = #{state} where tableNum = #{tableNum}")
    int update(DiningTable diningTable);

    /**
     * 通过餐桌编号删除餐桌
     * @param tableNum
     * @return
     */
    @Delete("delete from diningtable where tableNum = #{tableNum}")
    int delete(int tableNum);

    /**
     * 通过餐桌类型Id删除餐桌
     * @param typeId
     * @return
     */
    @Delete("delete from diningtable where typeId = #{typeId}")
    int delByTypeId(int typeId);

    /**
     * 获取数据条数
     * @return
     */
    @Select("select count(0) from diningtable")
    int dataSize();

    /**
     * 获取所有数据
     * @return
     */
    @Select("select * from diningtable")
//    @Results(value = {
//            @Result(property = "tableType", column = "typeId",one = @One(select = "com.xuetang9.t9.hotel.mapper.ITableTypeMapper.select",fetchType = FetchType.EAGER))
//    })
    List<DiningTable> selectAll();

    /**
     * 当页数据
     * @param start
     * @param pageSize
     * @return
     */
    @Select("select * from diningtable order by tableNum desc limit #{curr},#{size}")
    List<DiningTable> selectLimit(@Param("curr") int start, @Param("size") int pageSize);

    /**
     * 获取最大id
     * @return
     */
    @Select("select max(tableNum) from diningtable")
    long maxId();


    /**
     * 获取全部数据
     * @return
     */
    @Select("select * from diningtable")
    @Results(value = {
           @Result(property = "tableType", column = "typeId",one = @One(select = "com.xuetang9.t9.hotel.mapper.ITableTypeMapper.select",fetchType = FetchType.EAGER))
    })
    List<DiningTable> selectByAllByTable();
}
